package com.hdu.other.oneDimensionPreInfo;

import java.util.HashMap;
import java.util.Map;

public class lc1371 {
    class Solution {
        public int findTheLongestSubstring(String s) {
            /**
             * a e i o u
             * 0 - 偶数次
             * 1 - 偶数次
             */
            int status = 0;
            Map<Integer, Integer> status2firstIndex = new HashMap<>();
            status2firstIndex.put(0, -1);

            int ans = 0;

            for (int i = 0; i < s.length(); i++) {
                int index = getIndex(s.charAt(i));
                if (index != -1) {
                    /**
                     *  1 0 1 1 1
                     *  0 1 0 0 0
                     *
                     *  1 1 1 1 1
                     *  0 1 0 0 0
                     *  1 0 1 1 1
                     *
                     *
                     *  0 0 1 1 1
                     *  0 1 0 0 0
                     *
                     *  0 1 0
                     */
                    status ^= (1 << index);
                }
                if (status2firstIndex.containsKey(status)) {
                    ans = Math.max(ans, i - status2firstIndex.get(status));
                } else {
                    status2firstIndex.put(status, i);
                }
            }
            return ans;
        }

        int getIndex(char c) {
            switch (c) {
                case 'a':
                    return 0;
                case 'e':
                    return 1;
                case 'i':
                    return 2;
                case 'o':
                    return 3;
                case 'u':
                    return 4;
                default:
                    return -1;
            }
        }
    }
}
